package com.LeetCode.Tree;

import org.junit.Test;

public class isValidBST {
    long preVal = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        boolean ans = true;
        if(root == null) return true;
        ans = ans && isValidBST(root.left);
        if(preVal < root.val) preVal = root.val;
        else return false;
        ans = ans && isValidBST(root.right);
        return ans;
    }


    @Test
    public void test(){
        TreeNode node1 = new TreeNode(2);
        TreeNode node2 = new TreeNode(1);
        TreeNode node3 = new TreeNode(3);
        node1.left = node2;
        node1.right = node3;
        System.out.println(isValidBST(node1));
    }
}
